package com.zzedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzedu.common.utils.StringUtils;
import com.zzedu.domain.ZzThesaurusTag;
import com.zzedu.dto.ZzThesaurusTagDTO;
import com.zzedu.mapper.ZzThesaurusTagMapper;
import com.zzedu.service.IZzThesaurusTagService;
import org.springframework.stereotype.Service;
/**
 * 标签管理Service业务层处理
 * 
 * @author Mr.Wang
 * @date 2025-01-26
 */
@Service
public class ZzThesaurusTagServiceImpl extends ServiceImpl<ZzThesaurusTagMapper,ZzThesaurusTag> implements IZzThesaurusTagService
{

    @Override
    public LambdaQueryWrapper<ZzThesaurusTag> buildQuery(ZzThesaurusTagDTO zzThesaurusTag) {
        LambdaQueryWrapper<ZzThesaurusTag> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.like(StringUtils.isNotBlank(zzThesaurusTag.getTagName()), ZzThesaurusTag::getTagName, zzThesaurusTag.getTagName());

        lambdaQueryWrapper.apply(null!=zzThesaurusTag.getIncludeContentId(),"id in(select relation_id from zz_course_content_relate where relation_type=2 and content_id={0})",zzThesaurusTag.getIncludeContentId());

        lambdaQueryWrapper.apply(null!=zzThesaurusTag.getExcludeContentId(),"id not in(select relation_id from zz_course_content_relate where relation_type=2 and content_id={0})",zzThesaurusTag.getExcludeContentId());


        lambdaQueryWrapper.orderByDesc(ZzThesaurusTag::getId);
        return lambdaQueryWrapper;
    }
}